package pl.edu.agh.io.gpstracker.client.widget;

import pl.edu.agh.io.gpstracker.client.window.LoginWindow;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Side;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;

public class MainScreenWidget extends VLayout {

	private static final String WIDTH = "900";
	private static final String HEIGHT = "600";

	
	private Tab regUserTab;
	private Tab mobileUsersTab;

	private Tab monitoringTab;
	private Tab newTrack;
	private Tab statsTab;
	private Tab oldTracksTab;
	

	public MainScreenWidget() {
		initComponent();
		setSize(WIDTH, HEIGHT);
		setAlign(Alignment.CENTER);
		//
		blockInProgress();
		lockTabs(true);
	}

	private void initComponent() {
		
		LoginWindow loginWindow = new LoginWindow(this);
		loginWindow.show();
		
		final TabSet topTabSet = new TabSet();
		topTabSet.setTabBarPosition(Side.TOP);
		
		regUserTab = new Tab("Rejestracja uzytkownikow","users.png");
		regUserTab.setPane(new RegisterWidget());
		
		mobileUsersTab = new Tab("Zarzadzaj uzytkownikami", "zarza.png");
		mobileUsersTab.setPane(new ManageUserWidget());
		
		monitoringTab = new Tab("Monitoring", "monit.png");
		monitoringTab.setPane(new MonitoringWidget());
		
		newTrack = new Tab("Zdefiniuj nowa trase przejazdu", "zarza.png");
		final NewTrackWidget newTrackWidget = new NewTrackWidget();
		newTrack.setPane(newTrackWidget);
		newTrack.addTabSelectedHandler(new TabSelectedHandler() {
			
			@Override
			public void onTabSelected(TabSelectedEvent event) {
				newTrackWidget.loadUsers();
				
			}
		});
		
		oldTracksTab = new Tab("Przegladaj zakonczone trasy");
		oldTracksTab.setPane(new MonitoringWidget());
		
		statsTab= new Tab("Statystyki");
		statsTab.setPane(new RegisterWidget());
		

		topTabSet.addTab(regUserTab);
		topTabSet.addTab(mobileUsersTab);
		topTabSet.addTab(newTrack);
		topTabSet.addTab(monitoringTab);
		topTabSet.addTab(statsTab);
		topTabSet.addTab(oldTracksTab);
		
		setMembers(topTabSet);
	}
	
	private void blockInProgress(){
		oldTracksTab.setDisabled(true);
		statsTab.setDisabled(true);
	}

	/**
	 * 
	 * @param value
	 */
	public void lockTabs(boolean value) {
		mobileUsersTab.setDisabled(value);
		regUserTab.setDisabled(value);
		mobileUsersTab.setDisabled(value);
		monitoringTab.setDisabled(value);
		newTrack.setDisabled(value);
		//oldTracksTab.setDisabled(value);
	}

}
